package com.nikkerball.apps.darkhorse.rules;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Represents a condition used for a rule
 *
 * @author marius (created on 2010-12-05)
 */
public class Condition {

    // ----- instance fields -----

    private boolean satisfied;

    private ConditionType type;

    private String values;

    // ----- constructors -----

    public Condition() {
    }

    public Condition(ConditionType type, String values) {
        this.type = type;
        this.values = values;
    }

    // ----- public methods -----

    public void evaluate(String value) {
        String[] splitValues = StringUtils.split(getValues(), ';');
        List list = Arrays.asList(splitValues);
        this.satisfied = list.contains(value);
    }

    public ConditionType getType() {
        return this.type;
    }

    public void setType(ConditionType type) {
        this.type = type;
    }

    public String getValues() {
        return this.values;
    }

    public void setValues(String values) {
        this.values = values;
    }

    public boolean isSatisfied() {
        return this.satisfied;
    }

    public void setSatisfied(boolean satisfied) {
        this.satisfied = satisfied;
    }

}
